<?php
namespace app\index\controller;
use think\Controller;
use think\Session;
use think\Db;
use app\index\controller\Base;
class Reg extends Base{
	//注册
    public function index(){
		return $this->fetch('reg');
    }	
    public function check(){//用户登陆验证
      $username=input("post.username");
      $password=md5(sha1(input('post.password')));
      // $vcode=input("post.vcode");
      if(Db::name("user")->where('username',$username)->where('password',$password)->find()){//正确
        Session::set('username',$username); 
        return $this->success('登陆成功', 'Blog/index');
      }else{//用户名或密码错误
        return $this->error("用户名或密码错误！");
      }
    }
    public function register(){
      $username=input('post.username');
      $password=md5(sha1(input('post.password')));
      $email = input('post.email');
      $addtime = date("Y-m-d H:i:s");
        //密码和用户名正确
        if(db("user")->where('username',$username)->find()){
          $this->error('用户名已存在,请重新输入用户名！');
        }else{
            $data = [
              'username' => $username,
              'password' => $password,              
              'addtime' => $addtime,
            ];
            $add = db('user')->insert($data);
            return $this->success('注册成功,即将跳转到登陆页面……', 'Reg/index');
        }

    }

}